<?php

/**
 * @author honestphan
 * @copyright 2012
 */

 if(!$_SESSION['loged']){
         header('LOCATION: index.php?module=canbo&act=login');  
        exit();
 }
include('controller/c_thongke.php');     
include ('model/m_gioithieu.php');
$page = $_GET['act'];
 switch($page){
    case 'list':
    //Get language
    require('language/gioithieu/list.php');
    $heading_title = heading_title;
    $title = heading_title;
    $button_add = button_add;
    $button_edit = button_edit;
    $button_delete = button_delete;
    $theloai = the_loai;
    $thao_tac = thao_tac;
    $diadiem = dia_diem;
    $link_add ='index.php?module=gioithieu&act=add';
    $link_gtc ='index.php?module=gioithieu&act=edit&id=0';
     
    $timkiem = tim_kiem;
    $tieude = tieu_de;
    $button_gtc = gtc;
    
    if(empty($_POST['selected'])){
        $err['exist'] = chua_chon;
        $error_name = $err['exist'];
        }
        
    if(!$err){
        $valid = true;    
    }
    else{
        $valid = false;
    }
    
    //kiem tra du lieu cua from
    if(($_SERVER['REQUEST_METHOD']=='POST')&&$valid){
        foreach($_POST['selected'] as $id){
          delgioithieu($id);
        }  
        $_SESSION['success'] = del_success;
        //chuyen huong ve list
        header('LOCATION: '.$link_list);
     }
 
    if(trim($_POST['title'])==""){
         $err1['exist'] = chua_nhap_ten;
         //$error_warning = $err1['exist'];
     }
   
     if(!$err1){
            $valid1 = true;
     }else{
            $valid1 = false;
     }
   
     if(($_SERVER['REQUEST_METHOD']=='POST')&&$valid1){
        
          $list_gioithieu = getListgioithieu($start, $limit);
        
      }else{
           // kiem tra bien pages
            if($_REQUEST['page']==""){
               $page = 1;
            }
            else{
                $page = $_REQUEST['page'];
            }
            //get input for class page
            $limit = 5;
            $start = ($page - 1) * $limit;
            
            $list_gioithieu = getListgioithieu($start,$limit);
            $total = totalgioithieu();
            // paging
            $paging = new Pagination();
            $paging->total = $total;
            $paging->limit = $limit;
            $paging->url = "index.php?module=gioithieu&act=list&page={page}";
            $paging->page = $page;
            $pagination = $paging->render();
            //end phan trang by liem
             
      }
    require('view/template/gioithieu/list.tpl');
    break;
	
	//case them chuc danh
	case 'add':
	require('language/gioithieu/add.php');
	$heading_title = heading_title;
    $title = heading_title;
    $ma_gioithieu = ma_dac_sac;
	$ten_gioithieu = ten_dac_sac;
    $diachilienket = dia_chi_lien_ket;
    ///text
    $t_tendisan = ten_di_san;
    $t_huyen = huyen;
    $t_vung = vung;
    $t_loaidisan = loai_di_san;
    $t_diachi = dia_chi;
    $t_ynghialichsu = y_nghia_lich_su;
    $t_dinhkem = dinh_kem;
    
    $link_list = 'index.php?module=gioithieu&act=list';
    if($_POST['title']==""){
        $err['exist'] = chua_nhap_ten;
        $error_name = $err['exist'];
        }
        
        
    if(!$err){
        $valid = true;    
    }
    else{
        $valid = false;
    }
    if(($_SERVER['REQUEST_METHOD']=='POST')&&$valid)
    {
       insertgioithieu($_POST);
    $_SESSION['success'] = edit_success;
    //chuyen huong ve list
    header('LOCATION: '.$link_list);    
    }
    require('view/template/gioithieu/edit.tpl');
    break;
    
  
    case 'edit':
    require('language/gioithieu/edit.php');
    $heading_title = heading_title;
    $title = heading_title;
    $ma_gioithieu = ma_dac_sac;
    $ten_gioithieu = ten_dac_sac;
    $diachilienket = dia_chi_lien_ket;
      
    $t_tendisan = ten_di_san;
    $t_ynghialichsu = y_nghia_lich_su;
    
    
    $link_list = 'index.php?module=gioithieu&act=list';
    $id = $_REQUEST['id'];
    
    $gioithieu = getgioithieu($id);
    
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
    editgioithieu($id, $_POST);
    $_SESSION['success'] = edit_success;
    //chuyen huong ve list
    header('LOCATION: '.$link_list);    
    }
        
    require('view/template/gioithieu/edit.tpl');
    break; 
    
    
     //case sua dan toc
    case 'view':
    require('language/dac/gioithieu/view.php');
    $heading_title = heading_title;
    $title = heading_title;
    $ma_gioithieu = ma_dac_sac;
    $ten_gioithieu = ten_dac_sac;
    $diachilienket = dia_chi_lien_ket;
      
      
    $t_tendisan = ten_di_san;
    $t_huyen = huyen;
    $t_vung = vung;
    $t_loaidisan = loai_di_san;
    $t_diachi = dia_chi;
    $t_ynghialichsu = y_nghia_lich_su;
    $t_dinhkem = dinh_kem;
    
    $link_edit = 'index.php?module=gioithieu&act=edit&id='.$_REQUEST['id'];
    $link_list = 'index.php?module=gioithieu&act=list';
    $id = $_REQUEST['id'];
    $hoso = getgioithieu($id);
    
    require('view/template/gioithieu/gioithieu/view.tpl');
    break; 
    
    
   	
  
}
?>